Skip to content

Conversation

@samlurye
Copy link
Contributor

@samlurye samlurye commented Oct 1, 2025

Stack from ghstack (oldest at bottom):

This diff is an RFC for introducing a typed global configuration system in python for monarch, integrated with the hyperactor Attrs system and the hyperactor::global::config module. It introduces the py_configurable macro, which automatically generates typed python bindings for instances of hyperactor::attrs::Key<T>. Example usage:

py_configurable!(py, DEFAULT_TRANSPORT, "DefaultTransport", PyChannelTransport);

This means, "for the DEFAULT_TRANSPORT attribute, generate a python class with the following stub/functionality:

class DefaultTransport:
  @staticmethod
  def get() -> ChannelTransport: ... # Gets the current value of DEFAULT_TRANSPORT from the global config
  @staticmethod
  def set(val: ChannelTransport) -> None: ... # Sets the current value of DEFAULT_TRANSPORT in the global config

The leading py in the macro invocation is used in the implementation to indicate that PyChannelTransport needs to be converted to/from the actual type of the DEFAULT_TRANSPORT attribute (which is hyperactor::channel::ChannelTransport). If I were better at rust macros (or rust in general) I could probably figure out how to get rid of it.

I also added functionality to allow for a callback function when the config value is set from python. This could be useful when the root client needs to be re-initialized after setting DEFAULT_TRANSPORT.

Differential Revision: D83701581

… the Attrs system

This diff is an RFC for introducing a typed global configuration system in python for monarch, integrated with the hyperactor `Attrs` system and the `hyperactor::global::config` module. It introduces the `py_configurable` macro, which automatically generates typed python bindings for instances of `hyperactor::attrs::Key<T>`. Example usage:
```
py_configurable!(py, DEFAULT_TRANSPORT, "DefaultTransport", PyChannelTransport);
```
This means, "for the `DEFAULT_TRANSPORT` attribute, generate a python class with the following stub/functionality:
```
class DefaultTransport:
  @staticmethod
  def get() -> ChannelTransport: ... # Gets the current value of DEFAULT_TRANSPORT from the global config
  @staticmethod
  def set(val: ChannelTransport) -> None: ... # Sets the current value of DEFAULT_TRANSPORT in the global config
```
The leading `py` in the macro invocation is used in the implementation to indicate that `PyChannelTransport` needs to be converted to/from the actual type of the `DEFAULT_TRANSPORT` attribute (which is `hyperactor::channel::ChannelTransport`). If I were better at rust macros (or rust in general) I could probably figure out how to get rid of it.

I also added functionality to allow for a callback function when the config value is set from python. This could be useful when the root client needs to be re-initialized after setting `DEFAULT_TRANSPORT`.

Differential Revision: [D83701581](https://our.internmc.facebook.com/intern/diff/D83701581/)

[ghstack-poisoned]
samlurye added a commit that referenced this pull request Oct 1, 2025
… the Attrs system

This diff is an RFC for introducing a typed global configuration system in python for monarch, integrated with the hyperactor `Attrs` system and the `hyperactor::global::config` module. It introduces the `py_configurable` macro, which automatically generates typed python bindings for instances of `hyperactor::attrs::Key<T>`. Example usage:
```
py_configurable!(py, DEFAULT_TRANSPORT, "DefaultTransport", PyChannelTransport);
```
This means, "for the `DEFAULT_TRANSPORT` attribute, generate a python class with the following stub/functionality:
```
class DefaultTransport:
  staticmethod
  def get() -> ChannelTransport: ... # Gets the current value of DEFAULT_TRANSPORT from the global config
  staticmethod
  def set(val: ChannelTransport) -> None: ... # Sets the current value of DEFAULT_TRANSPORT in the global config
```
The leading `py` in the macro invocation is used in the implementation to indicate that `PyChannelTransport` needs to be converted to/from the actual type of the `DEFAULT_TRANSPORT` attribute (which is `hyperactor::channel::ChannelTransport`). If I were better at rust macros (or rust in general) I could probably figure out how to get rid of it.

I also added functionality to allow for a callback function when the config value is set from python. This could be useful when the root client needs to be re-initialized after setting `DEFAULT_TRANSPORT`.

Differential Revision: [D83701581](https://our.internmc.facebook.com/intern/diff/D83701581/)

ghstack-source-id: 313471101
Pull Request resolved: #1398
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 1, 2025
@meta-codesync
Copy link

meta-codesync bot commented Oct 1, 2025

@samlurye has exported this pull request. If you are a Meta employee, you can view the originating Diff in D83701581.

@samlurye samlurye closed this Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants